﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Kylin
{ 

    public class TableProperty {


        private Dictionary<string, int> integerDic = new Dictionary<string, int>();
        private Dictionary<string, string> stringDic = new Dictionary<string, string>();
        private Dictionary<string, float> floatDic = new Dictionary<string, float>();


        public void SetInt(string key, int value)
        {
            if (!WriteCheck(key)) return;

            integerDic.Add(key, value);
        }

        public void SetString(string key, string value)
        {
            if (!WriteCheck(key)) return;

            stringDic.Add(key, value);
        }

        public void SetFloat(string key, float value)
        {
            if (!WriteCheck(key)) return;

            floatDic.Add(key, value);
        }

        public int GetInt(string key)
        {
            if (!ReadCheck(key)) return int.MaxValue;

            return integerDic[key];
        }

        public string GetString(string key)
        {
            if (!ReadCheck(key)) return "";

            return stringDic[key];
        }

        public float GetFloat(string key)
        {
            if (!ReadCheck(key)) return float.MaxValue;

            return floatDic[key];
        }

        public void Unload()
        {
            integerDic.Clear();
            floatDic.Clear();
            stringDic.Clear();
        }


        private bool WriteCheck(string key)
        {
            if (integerDic.ContainsKey(key))
            {
                Debug.Log("Value with key: [" + key + "] already exist.");
                return false;
            }

            return true;
        }

        private bool ReadCheck(string key)
        {
            if (integerDic.ContainsKey(key)) return true;

            Debug.Log("Cannot find key: [" + key + "].");
            return false;

        }
    }

}
